/**
 * @param {number} num
 * @return {number}
 */
 var largestInteger = function(num) {
  let odd = [], even = []
  const arr = String(num).split('').map(v => Number(v))
  const n = arr.length
  const isOdd = new Array(n).fill(false)
  for(let i = 0; i<arr.length; i++) {
    if(arr[i] & 1) {
      odd.push(arr[i])
      isOdd[i] = true
    }else even.push(arr[i])
  }
  odd.sort((a,b) => a-b)
  even.sort((a,b) => a-b)
  let ans = []
  for(let i = 0; i<n; i++) {
    if(isOdd[i]) {
      ans[i] = odd.pop()
    } else {
      ans[i] = even.pop()
    }
  }
  return Number(ans.join(''))
};